//加载运行分析统计数据
import request from '../../utils/request'
import { whereType } from '../../types/suTypes/eventWhereType'
import { log } from 'console'
export const listGet = () => {
    return request.get("classes/EventData")
}
// 对象约束
interface wheresType {
    eventType?: number | null
    eventStart?: number | null
    alarmStart?: number | null
    restoreTime?: object | null
}
// 条件查询设备数据
export const listWhereGet = (whereData: whereType) => {
    let where: wheresType = {
        eventType: whereData.typevalue,
        eventStart: whereData.statevalue,
        alarmStart: whereData.alarmStart,
        restoreTime: null
    }
    for (const key in where) {
        // console.log(where[key]);
        if (where[key as keyof typeof where] == null) {
            delete where[key as keyof typeof where]
        }
    }
    let skip = (whereData.page - 1) * 10
    // 对传来的值时间进行判定，在就加入条件，不在就跳过
    if (whereData.timevalue != null) {
        where["restoreTime"] = { "$gte": { "__type": "Date", "iso": `${whereData.timevalue[0]}T00:00:00.000Z` }, "$lt": `${whereData.timevalue[1]}T00:00:00.000Z` }
    }
    let query = JSON.stringify(where)
    return request.get(`classes/EventData?limit=${whereData.limit}&skip=${skip}&where=${query}`)
}

// 查询表单分页
export const page = () => {
    return request.get
}
